//**************************************************************** 
//* Copyright (c) 2004 Ford Motor Company. All Rights Reserved. 
//* 
//* $$Workfile:   EconomicIndexDefDao.java  $$ 
//* $$Revision:   1.1  $$ 
//* $$Author:   JLOPE262  $$ 
//* $$Date:   Nov 21 2008 14:24:48  $$ 
//* 
//***************************************************************** 
package ar.com.ford.it.fullEconomics.persistence.dao;

import java.util.Collection;
import ar.com.ford.it.fullEconomics.persistence.dto.Teese01Economic;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesg01Plant;
import ar.com.ford.it.webengine.persistence.PersistenceUtil;
import com.ford.it.logging.ILogger;
import com.ford.it.logging.LogFactory;
import com.ford.it.persistence.PersistenceException;
import com.ford.it.persistence.PersistenceManager;
import com.ford.it.persistence.Query;
import com.ford.it.persistence.Transaction;

public class EconomicIndexDefDao extends Dao {
   private static final String CLASS_NAME = EconomicIndexDefDao.class
            .getName();

    private static final ILogger log = LogFactory.getInstance().getLogger(
            CLASS_NAME);

    /**
     * Busca los indices economicos
     * 
     * @param economicIndexDef
     * @return
     * @throws PersistenceException
     */
    public Collection findEconomicIndexDef(Teese01Economic economicIndexDef)
            throws PersistenceException {
        Collection resultCol = null;
        PersistenceManager pm = null;
        String METHOD_NAME = "findEconomicIndexDef";
        log.entering(CLASS_NAME, METHOD_NAME);
        pm = PersistenceUtil.getPersistenceManager();
        Query query = pm
                .newQuery("findEconomicIndexDef", Teese01Economic.class);
        query.setParameters(economicIndexDef);
        resultCol = (Collection) pm.executeQuery(query);

        log.exiting(CLASS_NAME, METHOD_NAME);
        return resultCol;
    }

    /**
     * Alta de Indice Economico ingresado por parametro
     * 
     * @param economicIndexDef
     * @throws PersistenceException
     */
    public void createEconomicIndexDef(Teese01Economic economicIndexDef)
            throws PersistenceException {
        Transaction tx = null;
        String METHOD_NAME = "createEconomicIndexDef";
        log.entering(CLASS_NAME, METHOD_NAME);
        tx = PersistenceUtil.getTransaction();
        tx.registerInsert(economicIndexDef);
        log.exiting(CLASS_NAME, METHOD_NAME);
    }

    public Teese01Economic getEconomicIndexDefForUpdate(Teesg01Plant plant,
            Integer economicIndexDefCode) throws PersistenceException {
        String METHOD_NAME = "getEconomicIndexDefForUpdate";
        log.entering(CLASS_NAME, METHOD_NAME);
        Teese01Economic result = null;
        Teese01Economic pk = new Teese01Economic();
        pk.setEese01PlantCodeC(plant);
        pk.setEese01EconNumberK(economicIndexDefCode);
        result = (Teese01Economic) super.getObjForUpdate(pk);
        log.exiting(CLASS_NAME, METHOD_NAME);
        return result;
    }

    /**
     * Elimina el indece Economico seleccionado
     * 
     * @param economicIndexDef
     * @throws PersistenceException
     */
    public void deleteEconomicIndexDef(Teese01Economic economicIndexDef)
            throws PersistenceException {

        String METHOD_NAME = "deleteEconomicIndexDef";
        log.entering(CLASS_NAME, METHOD_NAME);
        Transaction tx = PersistenceUtil.getTransaction();
        tx.registerDelete(economicIndexDef);
        log.exiting(CLASS_NAME, METHOD_NAME);
    }

    /**
     * Busqueda exacta de Indice Economico por EconomicNumberK
     * 
     * @param plant
     * @param codeEco
     * @return
     * @throws PersistenceException
     */
    public Teese01Economic findEconomicIndexByCode(Teesg01Plant plant,
            String codeEco) throws PersistenceException {
        String METHOD_NAME = "findEconomicIndexByCode";
        log.entering(CLASS_NAME, METHOD_NAME);
        Teese01Economic result = new Teese01Economic();
        Teese01Economic pk = new Teese01Economic();
        pk.setEese01EconNumberK(Integer.valueOf(codeEco));
        pk.setEese01PlantCodeC(plant);
        result = (Teese01Economic) super.getObjById(pk);
        log.exiting(CLASS_NAME, METHOD_NAME);
        return result;
    }

    /**
     * Busca si la descripcion que se quiere agregar ya se utilizo, solo se
     * filtra por planta
     * 
     * @param plant
     * @param desc
     * @return
     * @throws PersistenceException
     */
    public Teese01Economic findUnicDescription(Teesg01Plant plant, String desc)
            throws PersistenceException {
        String METHOD_NAME = "findUnicDescription";
        log.entering(CLASS_NAME, METHOD_NAME);
        Teese01Economic economicIndex = new Teese01Economic();
        Teese01Economic result = null;
        economicIndex.setEese01PlantCodeC(plant);
        economicIndex.setEese01EconNameN(desc);
        PersistenceManager pm = null;
        pm = PersistenceUtil.getPersistenceManager();
        Query query = pm.newQuery("findUnicDescription", Teese01Economic.class);
        query.setParameters(economicIndex);
        result = (Teese01Economic) pm.executeQuery(query);
        log.exiting(CLASS_NAME, METHOD_NAME);
        return result;
    }

    /**
     * Find All Economicn Index Filter by Plant
     * 
     * @param plant
     * @return
     * @throws PersistenceException
     */
    public Collection findAllEconomicIndex(Teesg01Plant plant)
            throws PersistenceException {
        String METHOD_NAME = "findAllEconomicIndex";
        log.entering(CLASS_NAME, METHOD_NAME);
        Collection result = null;
        String[] economic = { "eese01PlantCodeC" };
        Object[] values = { plant };

        result = super.findAll(new Teese01Economic(), economic, values);
        log.exiting(CLASS_NAME, METHOD_NAME);
        return result;
    }
}
